#include "napi/native_api.h"
#include "encoder/common.h"
#include "encoder/encoder.h"

static napi_value videoDecoder(napi_env env, napi_callback_info info)
{
    size_t argc = 2;
    napi_value args[4] = {nullptr};
    napi_get_cb_info(env, info, &argc, args , nullptr, nullptr);
    SampleInfo sampleInfo;
    size_t strLen;
    napi_get_value_string_utf8(env, args[0],nullptr, 0, &strLen);
    sampleInfo.inputPath.resize(strLen);

    // 创建回调
    napi_create_reference(env, args[3], 1, &sampleInfo.callbackRef);
    //创建编解码
    VideoEncoder *videoEncoder = new VideoEncoder();
    videoEncoder->EncodeInt(sampleInfo);
    return nullptr;
}

EXTERN_C_START
static napi_value Init(napi_env env, napi_value exports)
{
    napi_property_descriptor desc[] = {
        { "videodecoder", nullptr, videoDecoder, nullptr, nullptr, nullptr, napi_default, nullptr }
    };
    napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
    return exports;
}
EXTERN_C_END

static napi_module demoModule = {
    .nm_version = 1,
    .nm_flags = 0,
    .nm_filename = nullptr,
    .nm_register_func = Init,
    .nm_modname = "entry",
    .nm_priv = ((void*)0),
    .reserved = { 0 },
};

extern "C" __attribute__((constructor)) void RegisterEntryModule(void)
{
    napi_module_register(&demoModule);
}
